
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span></button>
    <h4 class="modal-title" id="myModalLabel">添加商品分类</h4>
</div>
<form id="cateForm" class="form-horizontal" action="{:U('Admin/Category/addCate')}" method="post">
    <div class="modal-body">
        <div class="row">
            <div class="col-sm-12">
                <div class="row">
                <input type="hidden" name="cateid" value="{$cateid}" />
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for="name"> <b class="red">分类名称：</b> </label>

                        <div class="col-sm-5">
                            <input name="name" data-rel="tooltip" type="text" placeholder="分类名称(必填)" data-placement="bottom" class="form-control col-sm-5" required aria-required="true" value="" />
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for="cate-select"> <b id="lb" class="red">上级分类：</b> </label>
                        <div class="col-sm-5">
                            <select class="chosen-select col-sm-5" name="parent" id="cate-select" data-placeholder="选择上级分类(必选)">
                                <option value=""></option>
                                <option value="0" selected="selected">顶级分类</option>
                            <if condition="!empty($cateRow)">
                            <foreach name="cateRow" item="val">
                                <option value="{$val[cate_id]}" {:$parent == $val[cate_id] ? 'selected="selected"' : ''}>{$val[cate_name]}</option>
                            </foreach>
                            </if>

                            <if condition="!empty($cateAll)">
                                <php>
                                    function showT($data, $style = 'mtop', $pid) {
                                        foreach ($data as $key => $val) {
                                            echo '<option class="'.$style.'" value="'.$val['cate_id'].'"';
                                            if ($pid == $val['cate_id']) {echo ' selected="selected"';}
                                            echo '>';
                                            echo $val[cate_name].'</option>';
                                            if (!empty($val['childs'])) {
                                                showT($val['childs'], 'mchild');
                                            }
                                        }
                                    }
                                    showT($cateAll, '', $cateOne['cate_parent']);
                                </php>
                            </if>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for="brand">品牌：</label>

                        <div class="col-sm-5">
                            <select multiple="" name="brand[]" class="chosen-select" id="select-brand" data-placeholder="选择品牌...">
                                <foreach name="brand" item="val">
                                    <option value="{$val[brand_id]}">{$val[brand_name]}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for="sort"> 排序：</label>

                        <div class="col-sm-3">
                            <input name="sort" data-rel="tooltip" type="text" placeholder="排序" data-placement="bottom" class="col-sm-6" value="" />
                        </div>
                    </div>

                    <div class="controls form-group ">
                        <label class="col-sm-3 control-label no-padding-right" for="isempty"> 是否显示： </label>

                        <div class="col-sm-2">
                            <label>
                                <input name="isshow" class="ace ace-switch ace-switch-3" type="checkbox" value="1" offval="0" checked>
                                <span class="lbl"></span>

                            </label>
                        </div>
                        <label class="col-sm-7 green">ON(首页菜单显示)，OFF(反之不显示)</label>
                    </div>

                    <h4 class="header blue bolder smaller col-sm-12">SEO信息</h4>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for="title"> 分类标题：</label>

                        <div class="col-sm-9">
                            <input name="title" data-rel="tooltip" type="text" placeholder="分类标题(必填)" class="form-control col-sm-12" value="" />
                        </div>
                    </div>



                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for="keyword">分类关键词：</label>

                        <div class="col-sm-9">
                            <div class="inline">
                                <input type="text" class="form-control" name="keyword" id="keyword-tags" value="" placeholder="输入分类的关键词" />
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for="descript"> 分类描述：</label>

                        <div class="col-sm-9">
                            <textarea name="descript" class="form-control" data-rel="tooltip" type="text" placeholder="分类描述" ></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer align-center">
        <button type="submit" class="btn btn-primary">保存</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
    </div>
</form>
<script type="text/javascript">
    jQuery(function($){
        $('[data-rel=tooltip]').tooltip({container:'body'});
        $('[data-rel=popover]').popover({container:'body'});
        $("#cateForm").validate({
            errorElement : 'span',
            errorClass : 'help-block col-sm-6 pull-right',
            focusInvalid : false,
            rules: {
                name: {
                    required: true,
                    strBetween: [2,30]
                },
                parent_id: {
                    required: true
                },
            },
            messages: {
                name: {
                    required: "分类名称不能为空",
                    strBetween: "长度2-30个字符"
                },
                parent_id: {
                    required: "请选择上级分类"
                },
            },
            highlight : function(element) {
                $(element).closest('.form-group').addClass('has-error');
            },
            success : function(label) {
                label.closest('.form-group').removeClass('has-error');
                label.remove();
            },
            errorPlacement : function(error, element) {
                element.parent('div').append(error);
            }
        });
        $('.chosen-select').chosen({allow_single_deselect:true});
        $(window)
        .off('resize.chosen')
        .on('resize.chosen', function() {
            $('.chosen-select').each(function() {
                 var $this = $(this);
                 $this.next().css({'width':'100%'});
            });
        }).trigger('resize.chosen');

        var tag_input = $('#keyword-tags');
            try{
                tag_input.tag(
                  {
                    placeholder:tag_input.attr('placeholder'),
                    //enable typeahead by specifying the source array
                    source: ace.vars['US_STATES'],//defined in ace.js >> ace.enable_search_ahead
                    /**
                    //or fetch data from database, fetch those that match "query"
                    source: function(query, process) {
                      $.ajax({url: 'remote_source.php?q='+encodeURIComponent(query)})
                      .done(function(result_items){
                        process(result_items);
                      });
                    }
                    */
                  }
                )

                //programmatically add a new
                var $tag_obj = $('#keyword-tags').data('tag');
            }
            catch(e) {
                //display a textarea for old IE, because it doesn't support this plugin or another one I tried!
                tag_input.after('<textarea id="'+tag_input.attr('id')+'" name="'+tag_input.attr('name')+'" rows="3">'+tag_input.val()+'</textarea>').remove();
                //$('#keyword-tags').autosize({append: "\n"});
            }
    });

</script>
